<?php
// NOTE: If you need to run a body onload script when the page is loaded, what you do is you
// declare and initialize a variable $onload_function = "functionname();" in the file
// that calls header.php.
require_once("functions.php");
require_once("database.php");

$my_city = Null;
if(isset($_SESSION['user'])){
  $userinfo = query_select("
    SELECT hash, username, default_city
    FROM user
    WHERE id = " . sql_escape($_SESSION['user'])
  );
  $rss = $userinfo[0]['hash'];
  $username = $userinfo[0]['username'];
  $my_city = $userinfo[0]['default_city'];
  if($my_city){
    $default = query_select("
      SELECT name
      FROM city
      WHERE id = " . $my_city
    );
    $defaultcityname = $default[0]['name'];
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
		<title>lifeprice.com: apartment listings, data, and information from across the country</title>
    
		<link rel="stylesheet" type="text/css" href="lifestyle.css">
    <!--[if IE]><link type="text/css" rel="stylesheet" href="ie.css" /><![endif]-->
    
		<link rel="shortcut icon" href="favicon.ico" >
	</head>
	<body <?php if(isset($onload_function)) echo 'onload="' . $onload_function . '"'?>>
		<div id = "content">
			<div id = "header">
			
				<div id = "leftcol">
						<a href = "./index.php"><img src = "./layout/logo.png"></a>
				</div>
				
				<div id = "rightcol">
				<div id = "bigbox" class = "login">
				<div id = "createcurved"></div>
				<div id = "headerbox">
			<?php
				if(!isset($_SESSION['user'])){
			?>
			
					<table>		
					<form method="post" action="dologin.php">
						<tr>
							<td>Username: </td> <td><input class="width" name="username" type="text" /> </td>
						</tr>
						<tr>
							<td>Password: </td> <td><input class="width" name="password" type="password" /></td> <td><input type="submit" value="Login" /></td>
						</tr>	
					</form>
						<tr>
							<td colspan = "2"><a href="createaccount.php">Create Account</a></td>
						</tr>
					</table>
					
				<?php }
					else {
						  echo 'Welcome, ' . $username . '! | '; 
						  if(user_admin()){
                echo '<a href="admin.php">Administer</a> | ';
						  }
						  echo '<a href="dologout.php">Logout</a> | ';
              echo '<a href="rss.php?h=' . $rss . '"><img src = "./layout/rssicon.png" style="vertical-align: sub"/></a><br />';
              if($my_city){
                echo 'Your default city is <a href="city.php?id=' . $my_city . '">' . ucwords($defaultcityname) . '</a> (<a href="setdefault.php?reset">Reset</a>)';
              }
					}
				?>
				</div>
					</div>
				</div> <!--rightcol end -->
				
			</div><!--header end -->
			<div id = "middle">
